package com.hst.capacity.domain.model.response.setting.line;

import com.hst.capacity.domain.model.entity.setting.airport.AirportEntity;
import com.hst.capacity.domain.model.entity.setting.line.CityLineEntity;
import com.hst.capacity.domain.model.entity.setting.line.IntercityLineEntity;
import com.hst.capacity.domain.model.entity.setting.price.AirportPriceEntity;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class IntercityLineVO {

    private String idLine;
    private String idCityLine;
    private String cityCode;
    private String cityLineName;
    private int status;
    private int hot;
    private int sort;

    private String intercityLineAlias;
    private String intercityLineName;
    private String idFranchisee;
    private String startCityCode;
    private String startCity;
    private String startCityName;
    private String startCityDisplayName;
    private String endCityCode;
    private String endCity;
    private String endCityName;
    private String endCityDisplayName;
    private String localServiceCall;
    private String smallExpressMemo;
    private String intercityLinePriceLink;
    private String memo;
    private Integer lineSort;
    private Integer financeBatch;
    private Integer onlineStatus;
    private Float couponDiscount;
    private Float lineSubsidy;
    private Float noTaskLineSubsidy;
    private Integer showTime;
    private Float taskInterval;
    private String carpoolOperateTime;
    private String idRelationLine;
    private List<String> startCityCodes = new ArrayList<>();
    private List<String> endCityCodes = new ArrayList<>();

    public IntercityLineVO(CityLineEntity clEntity, IntercityLineEntity icLineEntity) {

        this.idCityLine = clEntity.getIdCityLine();
        this.cityCode = clEntity.getCityCode();
        this.cityLineName = clEntity.getCityLineName();
        this.status = clEntity.getStatus();
        this.hot = clEntity.getHot();
        this.sort = clEntity.getSort();

        this.idLine = icLineEntity.getIdLine();
        this.intercityLineAlias = icLineEntity.getIntercityLineAlias();
        this.intercityLineName = icLineEntity.getIntercityLineName();
        this.idFranchisee = icLineEntity.getIdFranchisee();
        this.startCityCode = icLineEntity.getStartCityCode();
        this.startCity = icLineEntity.getStartCity();
        this.startCityName = icLineEntity.getStartCityName();
        this.startCityDisplayName = icLineEntity.getStartCityDisplayName();
        this.endCityCode = icLineEntity.getEndCityCode();
        this.endCity = icLineEntity.getEndCity();
        this.endCityName = icLineEntity.getEndCityName();
        this.endCityDisplayName = icLineEntity.getEndCityDisplayName();
        this.localServiceCall = icLineEntity.getLocalServiceCall();
        this.smallExpressMemo = icLineEntity.getSmallExpressMemo();
        this.intercityLinePriceLink = icLineEntity.getIntercityLinePriceLink();
        this.memo = icLineEntity.getMemo();
        this.lineSort = icLineEntity.getLineSort();
        this.financeBatch = icLineEntity.getFinanceBatch();
        this.onlineStatus = icLineEntity.getOnlineStatus();
        this.couponDiscount = icLineEntity.getCouponDiscount();
        this.lineSubsidy = icLineEntity.getLineSubsidy();
        this.noTaskLineSubsidy = icLineEntity.getNoTaskLineSubsidy();
        this.showTime = icLineEntity.getShowTime();
        this.taskInterval = icLineEntity.getTaskInterval();
        this.carpoolOperateTime = icLineEntity.getCarpoolOperateTime();
        this.idRelationLine = icLineEntity.getIdRelationLine();

        this.setCityCodes();
    }

    private void setCityCodes(){

        String startCode = this.startCityCode;
        String endCode = this.endCityCode;

        String startProvinceCode = startCode.substring(0, 2);
        startProvinceCode = startProvinceCode + "0000";
        this.startCityCodes.add(startProvinceCode);

        String endProvinceCode = endCode.substring(0, 2);
        endProvinceCode = endProvinceCode + "0000";
        this.endCityCodes.add(endProvinceCode);

        String start = startCode.substring(4, 6);
        String end = endCode.substring(4, 6);

        // 如果两个都是市一级
        if (start.equals("00") && end.equals("00")) {
            String startCityCode = startCode.substring(0, 4);
            startCityCode = startCityCode + "00";
            String endCityCode = endCode.substring(0, 4);
            endCityCode = endCityCode + "00";
            this.startCityCodes.add(startCityCode);
            this.endCityCodes.add(endCityCode);
        }
        // 两个都是区一级
        if (!start.equals("00") && !end.equals("00")) {
            String startCityCode = startCode.substring(0, 4);
            startCityCode = startCityCode + "00";
            String endCityCode = endCode.substring(0, 4);
            endCityCode = endCityCode + "00";

            this.startCityCodes.add(startCityCode);
            this.endCityCodes.add(endCityCode);

            this.startCityCodes.add(startCode);
            this.endCityCodes.add(endCode);
        }
        // 起点是市一级，终点不是市一级
        if (start.equals("00") && !end.equals("00")) {
            this.startCityCodes.add(startCode);
            String endCityCode = endCode.substring(0, 4);
            endCityCode = endCityCode + "00";

            this.endCityCodes.add(endCityCode);
            this.endCityCodes.add(endCode);

        }
        // 起点不是市一级终点是市一级
        if (end.equals("00") && !start.equals("00")) {
            String startCityCode = startCode.substring(0, 4);
            startCityCode = startCityCode + "00";
            this.startCityCodes.add(startCityCode);
            this.startCityCodes.add(startCode);
            this.endCityCodes.add(endCode);
        }
    }
}
